/**
 * CircleDetailActivity.java
 * com.jamin.aabill.ui
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-8-27 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.aabill.ui;

import java.util.ArrayList;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

import com.jamin.aabill.R;
import com.jamin.aabill.custom.PathClickListener;
import com.jamin.aabill.custom.PathLayout;
import com.jamin.aabill.custom.TopBar;
import com.jamin.aabill.custom.TopBarClickListener;
import com.jamin.aabill.dao.CircleDao;
import com.jamin.aabill.data.Circle;
import com.jamin.aabill.ui.base.BaseViewPagerActivityGroup;
import com.jamin.aabill.utils.AppConstant;
import com.jamin.aabill.utils.Utils;
import com.umeng.analytics.MobclickAgent;

/**
 * ClassName:CircleDetailActivity
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-8-27 下午3:34:34 
 */
public class CircleDetailActivityGroup extends BaseViewPagerActivityGroup{

	private static final String TAG = "CircleDetailActivityGroup ====wangjieming ";

	Circle circle = null;
	
	protected long circleId = -1;
	TopBar topBar = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.circle_detail_activity_group);
		circleId = getIntent().getLongExtra("circleId", -1);
		InitViewPager();
		initView();
	}

	private void initView() {
		topBar = (TopBar) findViewById(R.id.top_bar);
		topBar.setTopBarClickListener(new TopBarClickListener() {
			@Override
			public void rightBtnClick() {
				Intent intent = new Intent(CircleDetailActivityGroup.this , AddCircleBillActivity.class);
				intent.putExtra("circleId", circleId);
				startActivity(intent);
			}
			@Override
			public void right2BtnClick() {
				Intent intent = new Intent(CircleDetailActivityGroup.this , AddCircleMemberActivity.class);
				intent.putExtra("circleId", circleId);
				startActivity(intent);
			}
			@Override
			public void leftBtnClick() {
				finish();
			}
		});
	}

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
		CircleDao mDao = new CircleDao();
		circle = mDao.getCircle(circleId);
		topBar.setTitle(circle.getCircle_name());
		/**
		 * 由于三个子页面不能正常进入OnResume ，所以在ActivityGroup的Resume时，给子页面发送广播，让子页面刷新数据<br>
		 */
		
		sendBroadcast(new Intent(AppConstant.BILL_DETAIL_REFRESH_ACTION));
		Utils.log(TAG, "CircleDetailActivityGroup=========onResume");
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	/***********************************初始化ViewPager****************************************/


	/**
	 * 初始化ViewPager
	 */
	private void InitViewPager() {
		InitImageView();
		InitTextView();
		mPager = (ViewPager) findViewById(R.id.vPager);
		listViews = new ArrayList<View>();

		//addView CircleDetail
		Intent intent1 = new Intent(CircleDetailActivityGroup.this, CircleDetailActivity.class);
		intent1.putExtra("circleId", circleId);
		Window subActivity1 = getLocalActivityManager().startActivity("CircleDetailActivity" , intent1);
		View view1 = subActivity1.getDecorView();

		//addView BillList
		Intent intent2 = new Intent(CircleDetailActivityGroup.this, CircleBillListActivity.class);
		intent2.putExtra("circleId", circleId);
		Window subActivity2 = getLocalActivityManager().startActivity("CircleBillListActivity" , intent2);
		View view2 = subActivity2.getDecorView();


		//addView CircleMember
		Intent intent3 = new Intent(CircleDetailActivityGroup.this, CircleMemberListActivity.class);
		intent3.putExtra("circleId", circleId);
		Window subActivity3 = getLocalActivityManager().startActivity("CircleMemberListActivity" , intent3);
		View view3 = subActivity3.getDecorView();

		listViews.add(view1);
		listViews.add(view2);
		listViews.add(view3);
		mPager.setAdapter(new MyPagerAdapter(listViews));
		mPager.setCurrentItem(0);
		mPager.setOnPageChangeListener(new MyOnPageChangeListener());
	}

	/**
	 * 初始化动画
	 */
	private void InitImageView() {
		cursor = (ImageView) findViewById(R.id.cursor);
		bmpW = BitmapFactory.decodeResource(getResources(), R.drawable.group_cursor).getWidth();// 获取图片宽度
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		int screenW = dm.widthPixels;// 获取分辨率宽度
		offset = (screenW / 3 - bmpW) / 2;// 计算偏移量
		Matrix matrix = new Matrix();
		matrix.postTranslate(offset, 0);
		cursor.setImageMatrix(matrix);// 设置动画初始位置

	}




}

